import request from "@/utils/request";

// 获取PLC列表
export function getPlcList(params) {
  return request({
    url: '/plc-info/list',
    method: 'get',
    params
  })
}

export function addPlc(data) {
  return request({
    url: '/plc-info/add', 
    method: 'post',
    data
  })
}

// 更新PLC信息
export function updatePlc(data) {
  return request({
    url: '/plc-info/update', 
    method: 'post', 
    data
  })
}

// 删除PLC
export function deletePlc(plcId) {
  // 验证参数类型
  if (!Number.isInteger(plcId) || plcId <= 0) {
    return Promise.reject(new Error('plcId必须是正整数'));
  }
  return request({
    url: '/plc-info/delete',
    method: 'delete',
    params: { plcId },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}